package com.hontech.kaltaapp.ui.parts

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Button
import android.widget.FrameLayout
import com.hontech.kaltaapp.R
import com.hontech.kaltaapp.device.CleanInfo
import com.hontech.kaltaapp.device.clean
import com.hontech.kaltaapp.device.drawHeatCtrl
import com.hontech.kaltaapp.device.drawWater2
import com.hontech.kaltaapp.device.event.status
import com.hontech.kaltaapp.device.nozzleCtrl
import com.hontech.kaltaapp.device.partsCtrl
import com.hontech.kaltaapp.exception.ExecException
import com.hontech.kaltaapp.ui.dialog.ProgDialog
import com.hontech.kaltaapp.ui.dialog.runProg
import com.hontech.kaltaapp.ui.view.LabelInput
import com.hontech.kaltaapp.utils.onClick
import kotlinx.coroutines.delay

class CleanParts (context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val liKpa: LabelInput
    private val liC: LabelInput
    private val liWater: LabelInput
    private val liD: LabelInput
    private val liSteam: LabelInput

    companion object {
        private const val KPA_READY_TIMEOUT = 30 * 1000
    }

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.parts_clean, this)

        liKpa = view.findViewById(R.id.id_clean_li_kpa)
        liC = view.findViewById(R.id.id_clean_li_c)
        liWater = view.findViewById(R.id.id_clean_li_water)
        liD = view.findViewById(R.id.id_clean_li_d)
        liSteam = view.findViewById(R.id.id_clean_li_steam)

        val btn = view.findViewById<Button>(R.id.id_clean_btn_clean)
        btn.onClick { onClickStart() }
    }

    private suspend fun onClickStart() {
        runProg("清洗", "清洗") {
            val info = CleanInfo(
                liKpa.textInt(),
                liC.textInt(),
                liD.textInt(),
                liWater.textInt(),
                liSteam.textInt()
            )
            clean(info, it)
        }
    }

}























